package com.group.flagtivities;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;

public class Settings extends Activity implements OnClickListener{

	private static Button password;
	private static Button profile_picture;
	private static Button logout;
	private static ProgressBar logoutIndicator;
	
	public static final int RESULT_PROFILE_PICTURE = 1;
	public static final int RESULT_LOGOUT = 2;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		
		findViews();
		
		TextUtil.setFont((ViewGroup) findViewById(R.id.settings), getAssets());
		findViewById(R.id.settings).setOnClickListener(this);
	}

	private void findViews() {
		password = (Button) findViewById(R.id.password);
		profile_picture = (Button) findViewById(R.id.profile_picture);
		logout = (Button) findViewById(R.id.logout);
		logoutIndicator = (ProgressBar) findViewById(R.id.logoutIndicator);
	}
	
	@Override
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.settings:
			setResult(RESULT_CANCELED);
			finish();
			break;
		case R.id.password:
			startActivity(new Intent(this, Password.class));
			setResult(RESULT_CANCELED);
			finish();
			break;
		case R.id.profile_picture:
			setResult(RESULT_PROFILE_PICTURE);
			finish();
			break;
		case R.id.logout:
			password.setEnabled(false);
			profile_picture.setEnabled(false);
			logout.setEnabled(false);
			logout.setTextColor(Color.GRAY);
			logoutIndicator.setVisibility(View.VISIBLE);
			
			Timer timer = new Timer();
			timer.schedule(new TimerTask() {
				public void run() {
					setResult(RESULT_LOGOUT);
					finish();
				}
			}, 3000);
			break;
		}
	}

}
